package com.tjetc;

import java.io.IOException;
import java.io.RandomAccessFile;

public class T01RandomAccessFile {
    public static void main1(String[] args) throws IOException {
        RandomAccessFile file = new RandomAccessFile("hello.txt","rw");
        file.writeByte(97);//写一个字节
        file.writeShort(12345);//写short
        file.writeInt(123456789);
        file.writeUTF("你好");
        file.close();

    }
    public static void main2(String[] args) throws IOException {
        RandomAccessFile file = new RandomAccessFile("hello.txt","rw");//rw可读可写
        System.out.println(file.readByte());
        System.out.println(file.readShort());
        System.out.println(file.readInt());
        System.out.println(file.readUTF());
    }

    public static void main(String[] args) throws IOException {
        RandomAccessFile file = new RandomAccessFile("hello.txt","rw");//rw可读可写
        file.seek(3);//将文件指针定位在指定的偏移位置(字节数),指针从零开始
//        System.out.println(file.readByte());
//        System.out.println(file.readShort());
        System.out.println(file.readInt());
        System.out.println(file.readUTF());
    }

}
